﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.User;
using CE.Global;
using CE.Provider;

public partial class Provider_TravelInsurance_ProviderTIPromotion : System.Web.UI.Page
{
    public static Int64 _providercarpromoid = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        if (!IsPostBack)
        {
            ClearProcess();
            if (Request.Params["PRID"] != null)
            {
                Int32 _TAPromoid;
                if (Int32.TryParse(Request.Params["PRID"].ToString(), out _TAPromoid))
                {
                    ShowCarPromo(_TAPromoid);
                }
            }
        }
    }

    private void ShowCarPromo(Int64 ProviderTAPromoId)
    {
        TAPromotion _TAPromo = new TAPromotion();
        TAPromotionDB _TAPromodb = new TAPromotionDB();

        _TAPromo = _TAPromodb.GetProviderTAPromotion(ProviderTAPromoId);

        if (_TAPromo != null)
        {
            _providercarpromoid = Convert.ToInt64(_TAPromo.PromotionId.ToString());
            lblProviderTAPromoId.Text = _TAPromo.PromotionId.ToString();
            txtPromoTitle.Text = _TAPromo.PromotionTitle;
            txtPromoDescription.Text = _TAPromo.PromotionDescription;
            chkStatus.Checked = Convert.ToBoolean(_TAPromo.Status);

        }
    }

    public void ClearProcess()
    {
        _providercarpromoid = 0;
        lblProviderTAPromoId.Text = "0";
        txtPromoTitle.Text = "";
        txtPromoDescription.Text = "";
        chkStatus.Checked = true;
        lblMessage.Text = "";

    }

    protected void btnClearForm_Click(object sender, EventArgs e)
    {
        ClearProcess();
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            TAPromotion _TAPromo = new TAPromotion();
            TAPromotionDB _TAPromodb = new TAPromotionDB();

            _TAPromo.PromotionId = _providercarpromoid;
            _TAPromo.PromotionTitle = txtPromoTitle.Text.Trim();
            _TAPromo.PromotionDescription = txtPromoDescription.Text.Trim();
            _TAPromo.ProviderCompanyId = Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString());
            _TAPromo.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            _TAPromo.Status = Convert.ToBoolean(chkStatus.Checked.ToString());
            _TAPromo.PromotionId = _TAPromodb.Insert(_TAPromo);

            if (_TAPromo.PromotionId > 0)
            {
                ClearProcess();
                lblMessage.Text = "Saved successfully!";
            }
            else
            {
                lblMessage.Text = "Saving failed!";
            }
        }
    }
    protected void ibtBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("ViewProviderTIPromotion.aspx");
    }
}
